﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAO_DTO_WS.DAO;
using DAO_DTO_WS.DTO;

namespace LayoutTemplate
{
    public partial class WebForm13 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if ((Session["ID"].ToString() == "") || (int.Parse(Session["TinhTrang"].ToString()) != 3))
                Response.Redirect("TrangLoi.aspx?Error=9");
        }

        protected void btnDangKy_Click(object sender, EventArgs e)
        {
            ThanhVienDTO thanhvien = new ThanhVienDTO();
            bool test = false;
            thanhvien = ThanhVienDAO.LayThanhVien(tbTenDangNhap.Text.Trim());
            if (thanhvien.TinhTrang == -1)
            {
                thanhvien.TenThanhVien = tbTenDangNhap.Text.Trim();
                thanhvien.MatKhau = tbMatKhau.Text;
                thanhvien.Email = tbEmail.Text;
                thanhvien.HoTen = "member";
                thanhvien.NgaySinh = new DateTime(1990, 1, 1);
                thanhvien.GioiTinh = 1;
                thanhvien.TinhTrang = 1;
                thanhvien.TaiKhoan = 0;
                thanhvien.NguyenQuan = "";
                thanhvien.NoiO = "";
                thanhvien.DienThoai = "";
                thanhvien.Avatar = "";

                test = ThanhVienDAO.ThemMoi(thanhvien);
            }
            if (test)
            {
                if (int.Parse(Session["TinhTrang"].ToString()) == 3)
                    Response.Redirect("AdminDanhSach.aspx?id=1&tt=0&page=1");
               
            }
            else
            {
                Response.Redirect("AdminDangKyThanhVien.aspx");
            }
            
        }
    }
}
